<template>
	<view class="content">
		<form>
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-green"></text>
					<text class="text-xl text-bold">基本信息</text>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">区域</view>
				<picker class="align-start" @change="AreaChange" :value="areaIndex" :range="Areas">
					<view  :class="areaIndex==-1?'text-gray':''">
						{{areaIndex>-1?Areas[areaIndex]:'请选择区域'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">拖欠项目</view>
				<input placeholder="请输入拖欠项目" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">欠佣甲方</view>
				<input placeholder="请输入欠佣甲方" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">欠佣负责人</view>
				<input placeholder="请输入欠佣负责人" name="input"></input>
			</view>
			<view class="cu-form-group" v-if="applyInfo.type=='zs'">
				<view class="title">欠佣联系方式</view>
				<input placeholder="请输入欠佣联系方式" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">欠佣金额</view>
				<input placeholder="请输入欠佣金额" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">成交时间</view>
				<input placeholder="请输入成交时间" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">承诺付款时间</view>
				<input placeholder="请输入承诺付款时间" name="input"></input>
			</view>
		
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-green"></text>
					<text class="text-xl text-bold">拒绝付款原因</text>
				</view>
			</view>
			<view class="cu-form-group">
				<textarea placeholder="请输入拒绝付款原因" name="input"></textarea>
			</view>
			
			<view class="cu-form-group">
				<view class="title">追佣人姓名</view>
				<input placeholder="请输入追佣人姓名" name="input"></input>
			</view>
			<view class="cu-form-group" >
				<view class="title">追佣人公司</view>
				<input placeholder="请输入追佣人公司" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">追佣人联系方式</view>
				<input placeholder="请输入追佣人联系方式" name="input"></input>
			</view>
			
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-green"></text>
					<text class="text-xl text-bold">备注</text>
				</view>
			</view>
			<view class="cu-form-group">
				<textarea placeholder="请描述一下基本情况非必填" name="input"></textarea>
			</view>
		<view class="cu-bar bg-white margin-top">
			<view class="action">
				图片上传
			</view>
			<view class="action">
				{{applyInfo.imgList.length}}/20
			</view>
		</view>
		<view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in applyInfo.imgList" :key="index" @tap="ViewImage" :data-url="applyInfo.imgList[index]">
				 <image :src="applyInfo.imgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="ChooseImage" v-if="applyInfo.imgList.length<20">
					<text class='cuIcon-cameraadd'></text>
				</view>
			</view>
		</view>
		
		</form>
		<view style="height:60px;"> </view>
		<view class="bottom">立即发布</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				areaIndex: -1,
				Areas: ['锦江区', '武侯区', '成华区'],
				applyInfo: {
					radio: 'A',
					houseId:'',
					houseName:'',
					imgList: [],
					type:'',
					address:'',
					latitude:0,
					longitude:0
				}
			};
		},
		onLoad(option){
			this.applyInfo.type = option.type;
		},
		methods: {
			ChooseImage() {
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.applyInfo.imgList.length != 0) {
							this.applyInfo.imgList = this.applyInfo.imgList.concat(res.tempFilePaths)
						} else {
							this.applyInfo.imgList = res.tempFilePaths
						}
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.applyInfo.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '召唤师',
					content: '确定要删除这段回忆吗？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							this.applyInfo.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			selectHouse(){
				uni.navigateTo({
					url:'/pages/ruzhu/select'
				})
			},
			ChoseLocation(){
				var me=this;
				uni.chooseLocation({
				    success: function (res) {
				        me.applyInfo.address= res.address;
				        me.applyInfo.latitude=res.latitude;
				        me.applyInfo.longitude= res.longitude;
				    }
				});
			},
			AreaChange(e) {
				
				this.areaIndex = e.detail.value
				console.log(this.areaIndex);
			},
			
		}
	}
</script>

<style lang="scss">
	.content {
		.bottom {
			z-index:1000;
			position: fixed;
			bottom: 0;
			background-color: #007AFF;
			padding: 8px 0;
			width: 100%;
			font-size: 35upx;
			text-align: center;
			color: white;
		}
		.cu-form-group{
			.col-3{
				view{
					padding:2px 0;
				}
			}
		}
	}
	.image-lebel{
		margin: 0 auto;
	}
</style>
